package com.lc.user.express.ordermanagement;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.lc.user.express.BaseSecondActivity;
import com.lc.user.express.R;
import com.lc.user.express.app.AppContext;
import com.lc.user.express.httpserver.GetComment;
import com.lc.user.express.utils.GetToast;
import com.lc.user.express.view.ContainsEmojiEditText;
import com.lc.user.express.view.StarView;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.view.StartView;


/**
 * Created by Administrator on 2016/5/6. 评价
 */
public class CommentActivity extends BaseSecondActivity {
    private StarView starView;
    private ContainsEmojiEditText et_input;
    private int star = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_comment);
        setTitle("评价");
        et_input = (ContainsEmojiEditText) findViewById(R.id.et_input);
        starView = (StarView) findViewById(R.id.sv);
        starView.setSelect(-1);
        starView.setOnItemSelectListener(new StartView.OnItemSelectListener() {
            @Override
            public void onItemSelect(int i) {
                star = i + 1;
            }
        });
        ((TextView) findViewById(R.id.tv_public)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (TextUtils.isEmpty(et_input.getText().toString().trim())){
                    Toast.makeText(cnt, "评价不能为空", Toast.LENGTH_SHORT).show();
                }else {
                    comment();
                }
                
                

            }
        });
    }

    private void comment() {
        new GetComment(AppContext.myPreferences.getUid(), getIntent().getStringExtra("orderid"), et_input.getText().toString().trim(), star, new AsyCallBack<Object>() {
            @Override
            public void onSuccess(String toast, int type, Object info) throws Exception {
                super.onSuccess(toast, type, info);
                if ("1".equals(info)) {
                    if (OrderManagementFragment.onRefreshOrderData != null) {
                        OrderManagementFragment.onRefreshOrderData.onRefresh();
                    }
                    if (OrderDetailsActivity.onRefreshView != null) {
                        OrderDetailsActivity.onRefreshView.onRefresh();
                    }
                    finish();
                }
            }

            @Override
            public void onEnd(String toast, int type) throws Exception {
                super.onEnd(toast, type);
                if (!TextUtils.isEmpty(toast)) GetToast.useString(cnt, toast);
            }
        }).execute(cnt);//调接口
    }
}
